const Room = require("./room");

let roomManager = (function () {
	let that = {};
	let roomList = [];
	// 创建24个房间
	for (let i = 0; i < 24; i++) {
		let room = new Room(i + 1);
		roomList.push(room);
	}

	that.getAllRoomInfo = function (pak) {
		return { err: null, info: roomList };
	};

	// 往房间中添加一个玩家
	that.roomAddPlayer = function (player, data, type) {
		let room = roomList[data.roomID - 1];
		if (room.colorList.length <= 0) {
			return false;
		}
		room.playerList.push(player);
		player.roomID = data.roomID;
		player.seatID = data.seatID;
		player.color = room.colorList.pop();
		room.sendMsgToRoomMember(type);
		return true;
	};
	that.startGame = function (data) {
		let room = roomList[data.data.roomID - 1];
		room.playerList[0].sendMsg({
			type: "startGame",
			isGuangbo: true,
			data: room.playerList[0].color,
		});
		room.playerList[1].sendMsg({
			type: "startGame",
			isGuangbo: true,
			data: room.playerList[1].color,
		});
		return { err: null, info: "开始游戏" };
	};
	that.getRoomInfo = function (data) {};
	that.moveChess = function (data) {
		
	};

	return that;
})();
module.exports = roomManager;
